package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Random;
import org.testng.annotations.Test;
import static com.example.fw.ContactHelper.MODIFICATION;
import com.example.utils.SortedListOf;

public class ContactModificationTests extends TestBase {
	
	@Test(dataProvider = "randomValidContactGenerator")
	public void modifyFirstNameContact( ContactData contact ){
		// save old state
		SortedListOf<ContactData> oldList = app.getModel().getContact();
		
		Random rnd 	= new Random();
		int indx	= rnd.nextInt(oldList.size() - 1);		
		
		// do some changes
		app.getContactHelper().modifyContact(contact, indx, MODIFICATION);
		
		// save a new state
		SortedListOf<ContactData> newList = app.getModel().getContact();
		
		// compare old and new state
		assertThat(newList, equalTo(oldList.without(indx).withAdded(contact)));
	}
}
